package cn.com.wxd.amumu.search.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.com.wxd.amumu.search.entity.IndexEntity;
import cn.com.wxd.amumu.search.service.ManageService;

/**
 * Title:
 * Description:
 * <p>
 * Company: Amumu系统
 * Copyright: Copyright (c) 2017
 * All right reserved.
 * Created by WangXuDong on 2017/8/18.
 *
 * @author WangXuDong
 * @version 1.0
 */
@RestController
@RequestMapping("/manage")
public class ManagementCtl {

    private static final Logger log = LoggerFactory.getLogger(ManagementCtl.class);
    private ManageService manageService = new ManageService();

    @RequestMapping("addindex")
    public AjaxResult addIndex(@RequestBody List<IndexEntity> indexEntitylist) {
        if (indexEntitylist != null && indexEntitylist.size() > 0) {
            try {
                manageService.addData(indexEntitylist);
                return AjaxResult.successResult();
            } catch (Exception e) {
                log.error(e.getMessage(),e);
                return AjaxResult.errorResult(e.getMessage(),e);
            }
        }
        return AjaxResult.failureResult("参数错误!");
    }

    @RequestMapping("updateindex")
    public AjaxResult updateIndex(@RequestBody IndexEntity indexEntity) {
        if (indexEntity != null && indexEntity.getId() != null) {
            try {
                manageService.updateData(indexEntity);
                return AjaxResult.successResult();
            } catch (Exception e) {
                log.error(e.getMessage(),e);
                return AjaxResult.errorResult(e.getMessage(),e);
            }
        }
        return AjaxResult.failureResult("参数错误!");
    }

    @RequestMapping("delindex")
    public AjaxResult delIndex(@RequestBody String[] ids) {
        if (ids != null && ids.length > 0) {
            try {
                manageService.delData(ids);
                return AjaxResult.successResult();
            } catch (Exception e) {
                log.error(e.getMessage(),e);
                return AjaxResult.errorResult(e.getMessage(),e);
            }
        }
        return AjaxResult.failureResult("参数错误!");
    }
}
